package com.mytaobao.main.firsttab.func.menu;

import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baseproject.adapter.ItemViewDelegate;
import com.baseproject.adapter.ViewHolder;
import com.mytaobao.R;
import com.mytaobao.util.Const;

import java.util.ArrayList;
import java.util.List;

/**
 * 十个菜单项
 */
public class MenuItemDelagate implements ItemViewDelegate<ItemMenu> {
    private ItemMenu mDataMenu;

    public MenuItemDelagate() {
        mDataMenu = new ItemMenu();
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.adapter_firsttab_menu;
    }

    @Override
    public int getItemViewType() {
        return Const.TYPE_MENU;
    }

    @Override
    public void convert(ViewHolder holder, int position) {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

    @Override
    public ViewHolder createViewHolder(Context context, ViewGroup parent) {
        View itemView = LayoutInflater.from(context).inflate(getItemViewLayoutId(), parent, false);
        ViewHolder holder = new MenuViewHolder(context, itemView);
        return holder;
    }

    private final class MenuViewHolder extends ViewHolder {
        List<LinearLayout> lls = new ArrayList<LinearLayout>();
        List<Integer> llids = new ArrayList<Integer>() {{
            add(R.id.tianmao);
            add(R.id.juhuasuan);
            add(R.id.tianmaoguoji);
            add(R.id.waimai);
            add(R.id.tianmaochaoshi);
            add(R.id.chongzhizhongxin);
            add(R.id.alilvxing);
            add(R.id.lingjinbi);
            add(R.id.daojia);
            add(R.id.fenlei);
        }};

        public MenuViewHolder(Context context, View itemView) {
            super(context, itemView);
            for (int i = 0; i < llids.size(); i++) {
                LinearLayout item = (LinearLayout) itemView.findViewById(llids.get(i));
//                item.setOnClickListener(FirstTabRecyclerAdapter.this);
                lls.add(item);
            }

            for (int i = 0; i < lls.size(); i++) {
                ((ImageView) lls.get(i).getChildAt(0)).setImageResource(mDataMenu.getmDataMenuImageRid().get(i));
                ((TextView) lls.get(i).getChildAt(1)).setText(mDataMenu.getmDataMenuTextRid().get(i));
            }
        }
    }

    @Override
    public void updateData(ItemMenu itemMenu) {

    }

    @Override
    public int getItemCount() {
        return 1;
    }
}
